<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-adx__ocpxccount}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="账户ID">
          <el-input v-model="dataForm.id" placeholder="账户ID" clearable></el-input>
        </el-form-item>
        <el-form-item label="账户名称">
          <el-input v-model="dataForm.name" placeholder="账户名称" clearable></el-input>
        </el-form-item>

          <el-form-item label="商务">
            <el-select v-model="dataForm.business" placeholder="选择运营人员" filterable clearable>
              <el-option v-for="item in businessList " :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>

                 <el-form-item label="所属产品" prop="productChannel">
           <el-select v-model="dataForm.productChannel" placeholder="选择运营人员" filterable clearable>
              <el-option v-for="item in productList " :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue">
              </el-option>
            </el-select>
      </el-form-item>
         <el-form-item label="所属媒体" prop="mediaChannel">
         <el-select v-model="dataForm.mediaChannel" placeholder="选择运营人员" filterable clearable>
              <el-option v-for="item in mediaList " :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue">
              </el-option>
            </el-select>
      </el-form-item>


        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('adx:ocpxaccount:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('adx:ocpxaccount:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="账户ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="name" label="账户名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="apiId" label="所属接口" header-align="center" align="center">
          <template slot-scope="scope">
            {{ $getDictLabel("configList",scope.row.apiId) }}
          </template>
        </el-table-column>
        <el-table-column prop="keyType" label="结算指标" header-align="center" align="center">
           <template slot-scope="scope">
            {{ $getDictLabel("typeList", scope.row.keyType) }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="type" label="运营模式（1正常模式，2赔付模式）" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="business" label="所属商务" header-align="center" align="center"></el-table-column>
        <el-table-column prop="userName" width="100" label="所属运营" header-align="center" align="center"></el-table-column>
        <el-table-column prop="productChannel" label="产品渠道" header-align="center" align="center">
          <template slot-scope="scope">
            {{ $getDictLabel("productList", scope.row.productChannel) }}
          </template>
        </el-table-column>
        <el-table-column prop="mediaChannel" label="媒体渠道" header-align="center" align="center">
          <template slot-scope="scope">
            {{ $getDictLabel("mediaList", scope.row.mediaChannel) }}
          </template>
        </el-table-column>
        <el-table-column prop="dayLimitNumber" label="当日限量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="totalLimitNumber" label="总的限量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="per" label="整体回传比例" header-align="center" align="center">
           <template slot-scope="scope">
               <el-progress :text-inside="true" :stroke-width="26" :percentage="scope.row.per*100"></el-progress>
            </template>
        </el-table-column>
        <!-- <el-table-column prop="mediaKey" label="媒体的key" header-align="center" align="center"></el-table-column>
        <el-table-column prop="channelId" label="渠道ID" header-align="center" align="center"></el-table-column> -->
        <!-- <el-table-column prop="taskId" label="任务ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="tagId" label="广告位ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="planId" label="计划ID" header-align="center" align="center"></el-table-column> -->
        <!-- <el-table-column prop="callTypeRelat" label="回传对应关系" header-align="center" align="center"></el-table-column>
        <el-table-column prop="productPer" label="产品端指标回传率" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="状态（1开始，2关闭）" header-align="center" align="center"></el-table-column>
        <el-table-column prop="callType" label="回掉去重（1不去重，2去重）" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateTime" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" header-align="center" align="center"></el-table-column> -->
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('adx:ocpxaccount:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <!-- <el-button v-if="$hasPermission('adx:dahanghaiaccount:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button> -->
            <el-button  type="text" size="small" @click="ocpxFindHander(scope.row.id)">查看监测</el-button>
            <el-button  type="text" size="small" @click="copyAccount(scope.row.id)">复制账户</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <OcpxFind v-if="ocpxVisible" ref="ocpxFind" @refreshDataList="getDataList"></OcpxFind>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './ocpxaccount-add-or-update'
import OcpxFind from './ocpxaccount-ocpx'
import { getDictDataList } from '@/utils'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/adx/ocpxaccount/page',
        getDataListIsPage: true,
        exportURL: '/adx/ocpxaccount/export',
        deleteURL: '/adx/ocpxaccount',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      businessList:[],
      mediaList:[],
      productList:[],
      productCallTypeList:[],
      configList:[],
      ocpxVisible: false   // 新增／更新，弹窗visible状态
    }
  },
  components: {
    AddOrUpdate,
    OcpxFind
  },
  mounted() {
   
    this.getBusinessDict();
    this.getProductList();
    this.getMediaList();
    this.getCallTypeList();
    this.getConfigList();
  },
  methods:{
    ocpxFindHander (id) {
      this.ocpxVisible = true
      this.$nextTick(() => {
        this.$refs.ocpxFind.dataForm.id = id
        this.$refs.ocpxFind.init()
      })
    },
      copyAccount(id){
      //复制账户的功能
      this.$confirm('确认要复制当前账户吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
               return this.$http.get('adx/ocpxaccount/copy?id='+id).then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg)
              }
              this.getDataList()
              this.$message('账户复制成功')
               })
          }).catch(() => {
                   
        });
    },
    getBusinessDict() {
      this.businessList = getDictDataList("businessList")
    },
    getCallTypeList(){
      this.callTypeList = getDictDataList("callTypeList")
    },
    getMediaList() {
      this.mediaList = getDictDataList("mediaList")
    },
       getProductList() {
      this.productList = getDictDataList("productList")
    },
    getConfigList( ) {
      this.configList = getDictDataList("configList")

    },
  }
}
</script>
